#include <unistd.h> // for readlink
#include <limits.h> // for PATH_MAX
#include <libgen.h> // for dirname
#include <string>
#include <iostream>

#include "DataSaver.h"
std::string getExecutablePath()
{
    char buffer[PATH_MAX];
    ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);

    if (len == -1)
    {
        std::cerr << "Error getting executable path" << std::endl;
        return "";
    }

    buffer[len] = '\0';     // 确保字符串终止
    return dirname(buffer); // 返回目录部分
}
int main(int argc, char *argv[])
{
    std::string exeDir = getExecutablePath();
    if (!exeDir.empty())
    {
        std::cout << "Executable directory: " << exeDir << std::endl;
    }

    DataSaver *_saver[4];
    for (int i = 0; i < 4; i++)
    {
        _saver[i] = new DataSaver(exeDir + "/", i + 1);
        _saver[i]->start();
    }

    while (true)
    {
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }
    return 0;
}